package com.uenpay.oem.widget.behavior;

import android.content.Context;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CoordinatorLayout;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by liulou on 2017/5/4.
 * desc:
 */

public class HomeBarBehavior extends AppBarLayout.ScrollingViewBehavior {
    View mTitleBarCollapse, mTitleBarExpand;

    public HomeBarBehavior(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) {
        float v = child.getTop() * 1f / dependency.getMeasuredHeight();
        dependency.setAlpha(v);
        if (v < 0.4f) {
            mTitleBarCollapse.setVisibility(View.VISIBLE);
            mTitleBarExpand.setVisibility(View.GONE);
        } else {
            mTitleBarCollapse.setVisibility(View.GONE);
            mTitleBarExpand.setVisibility(View.VISIBLE);
        }

        return super.onDependentViewChanged(parent, child, dependency);
    }

    public void setTitleBars(View titleBarCollapse, View titleBarExpand) {
        this.mTitleBarCollapse = titleBarCollapse;
        this.mTitleBarExpand = titleBarExpand;
    }
}
